import {Component, ViewChild} from '@angular/core';
import {AlertController, Content, IonicPage} from 'ionic-angular';
import {DishProvider} from "../../../providers/DishProvider";
import {KitProvider} from "../../../core/foundations/KitProvider";
import {CartProvider} from "../../../providers/cartProvider";

/**
 * Generated class for the MenuPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-menu',
  templateUrl: 'menu.html',
})
export class EmployeeMenuPage {
  @ViewChild(Content) content: Content;
  dishes: any;
  dish: any;
  data: any;
  carts;

  constructor(public dishProd: DishProvider,
              public cartProd: CartProvider,
              public kit: KitProvider, private alertCtrl: AlertController) {


  }


  ionViewDidLoad() {
    this.carts = this.cartProd.toMap();
    let loading = this.kit.loadingPresent();
    this.dishProd.getDishesCart().subscribe(res => {
        loading.dismiss();
        this.data = res;
        console.log(this.data);
      }
    )
  }

  numberOfCarts(dish_id: number): number {
    let cart = this.carts.get(dish_id.toString());

    if (cart != null) {
      return cart.Number_of_Orders;
    }
    else return 0;
  }

  onNumChanged(event, dish) {
    this.kit.cart.changeCart(dish, event).subscribe(res =>console.log('res',res));

  }

  alert(d) {
    let alert = this.alertCtrl.create({
      message: '<img src="http://www.ezbe.cn/storage/' + d + '">'
    });
    alert.present();
  }
}





